package com.nmsl.membership.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.membership.domain.ValueStorage;
import com.nmsl.membership.service.IValueStorageService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 储值管理Controller
 * 
 * @author liuyan
 * @date 2025-02-15
 */
//储值管理
@RestController
@RequestMapping("/membership/valuestorage")
public class ValueStorageController extends BaseController
{
    @Autowired
    private IValueStorageService valueStorageService;
    /**
     * 查询储值管理列表
     */
    @PreAuthorize("@ss.hasPermi('membership:valuestorage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ValueStorage valueStorage)
    {
        startPage();
        List<ValueStorage> list = valueStorageService.selectValueStorageList(valueStorage);
        return getDataTable(list);
    }

    //充值:查询
    //充值前查询表头
    @PreAuthorize("@ss.hasPermi('membership:valuestorage:query')")
    @GetMapping("/{chongzhiqianchaxun}")
    public AjaxResult selectById(@PathVariable("membershipId") Long membershipId)
    {
        System.out.println( membershipId);
        return success(valueStorageService.chongzhiqianchaxun(membershipId)) ;

    }



    /**
     * 导出储值管理列表
     */
    @PreAuthorize("@ss.hasPermi('membership:valuestorage:export')")
    @Log(title = "储值管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ValueStorage valueStorage)
    {
        List<ValueStorage> list = valueStorageService.selectValueStorageList(valueStorage);
        ExcelUtil<ValueStorage> util = new ExcelUtil<ValueStorage>(ValueStorage.class);
        util.exportExcel(response, list, "储值管理数据");
    }
    /**
     * 获取储值管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('membership:valuestorage:query')")
    @GetMapping(value = "/{storageId}")
    public AjaxResult getInfo(@PathVariable("storageId") Long storageId)
    {
        return success(valueStorageService.selectValueStorageByStorageId(storageId));
    }

    /**
     * 新增储值管理
     */
    @PreAuthorize("@ss.hasPermi('membership:valuestorage:add')")
    @Log(title = "储值管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ValueStorage valueStorage)
    {
        return toAjax(valueStorageService.insertValueStorage(valueStorage));
    }

    /**
     * 修改储值管理
     */
    @PreAuthorize("@ss.hasPermi('membership:valuestorage:edit')")
    @Log(title = "储值管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ValueStorage valueStorage)
    {
        return toAjax(valueStorageService.updateValueStorage(valueStorage));
    }

    /**
     * 删除储值管理
     */
    @PreAuthorize("@ss.hasPermi('membership:valuestorage:remove')")
    @Log(title = "储值管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storageIds}")
    public AjaxResult remove(@PathVariable Long[] storageIds)
    {
        return toAjax(valueStorageService.deleteValueStorageByStorageIds(storageIds));
    }
}
